package com.tensquare.qa.controller;

import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.ProblemService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("problem")
@CrossOrigin
public class ProblemController {

    @Autowired
    private ProblemService problemService;


    //最新回答列表（sql查询，使用本地sql查询）
    //最新回复的问题显示在上方， 按回复时间降序排序。
    @GetMapping("newlist/{label}/{page}/{size}")
    public Result findNewProblemList(@PathVariable String label, @PathVariable int page, @PathVariable int size){
        PageResult<Problem> newProblemList = problemService.findNewProblemList(label, page, size);
        return new Result(true,StatusCode.OK,"最新回答列表",newProblemList);
    }



    //热门问答列表
    //按回复数降序排序
    @GetMapping("hotlist/{label}/{page}/{size}")
    public Result findhostProblemList(@PathVariable String label,@PathVariable int page,@PathVariable int size){
        PageResult<Problem> problemList= problemService.findhostProblem(label,page,size);
          return new Result(true,StatusCode.OK,"热门回答列表",problemList);
    }
}
